package ysu.sxm.ptjc.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ysu.sxm.ptjc.Dao.DefectRecordMapper;
import ysu.sxm.ptjc.Domin.RecordList;
import ysu.sxm.ptjc.Service.DefectRecordService;
import ysu.sxm.ptjc.pojo.DefectQueryInfo;
import ysu.sxm.ptjc.pojo.DefectRecordInfo;
import ysu.sxm.ptjc.pojo.SignInfo;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

@Service
public class DefectRecordServiceImpl extends ServiceImpl<DefectRecordMapper, DefectRecordInfo> implements DefectRecordService {
    @Autowired
    DefectRecordMapper defectRecordMapper;

    @Override
    public boolean findOneByProduceIdAndLineId(String produceid, int lineid) {
        QueryWrapper<DefectRecordInfo> wrapper = new QueryWrapper<>();
        //根据用户名查询用户对象
        wrapper.eq("produce_id",produceid).eq("line_id",lineid);
        System.out.println(this.getOne(wrapper));
        if(this.getOne(wrapper)==null){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean addRecord(DefectRecordInfo defectRecordInfo) {
        defectRecordInfo.setRecordTime(new Timestamp(System.currentTimeMillis()));
        return this.save(defectRecordInfo);
    }

    @Override
    public boolean addtest(DefectRecordInfo defectRecordInfo) {
        return this.save(defectRecordInfo);
    }

    @Override
    public List<RecordList> AddRecordList(SignInfo signInfo) {
        DateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
        return defectRecordMapper.getOperatorAddList(signInfo.getUser_id(),sdf.format(signInfo.getSignBeginTime()));
    }

    @Override
    public boolean update(DefectRecordInfo defectRecordInfo){
        QueryWrapper<DefectRecordInfo> wrapper = new QueryWrapper<>();
        //根据用户名查询用户对象
        wrapper.eq("record_id",defectRecordInfo.getRecordId());
        return this.update(defectRecordInfo,wrapper);
    }
}
